package com.tsing.bms.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tsing.bms.entity.Repairs;
import com.tsing.bms.vo.req.RepairsPageReqVo;
import com.tsing.bms.vo.resp.RepairsRespVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author TheTsing
 * @since 2021-03-29
 */
public interface RepairsMapper extends BaseMapper<Repairs> {

    @Select("<script>select r.*,u.nick_name userName,u.phone userPhone,concat(b.name,'-',un.name,'-',h.name) houseName,ma.name maintainName\n" +
            "from t_repairs r\n" +
            "left join t_house h on r.house_id=h.id\n" +
            "left join t_user u on u.id=h.household_id\n" +
            "left join t_unit un on h.unit_id=un.id\n" +
            "left join t_building b on b.id=un.building_id\n" +
            "left join t_maintain ma on ma.id=r.maintain_id" +
            "<where>\n" +
            "<if test=\"reqVo.name!=null and reqVo.name!=''\">and u.nick_name like concat('%',#{reqVo.name},'%')</if>\n" +
            "<if test=\"reqVo.typeName!=null and reqVo.typeName!=''\">and ma.name like concat('%',#{reqVo.typeName},'%')</if>\n" +
            "</where>\n" +
            "order by r.id desc" +
            "</script>")
    List<RepairsRespVo> repairsPage(RepairsPageReqVo reqVo, Page<Repairs> page);

    @Select("select * from t_repairs where id=#{id}")
    RepairsRespVo getRepairsById(@Param("id") String id);

}
